<template>
	<div class="body_inner">

		<div class="password_page">
			<div class="page_top">
				<div @click="goback()"><i class="xi-arrow-left" style="font-size: 22px;"></i></div>

				<div class="allMenu_btn" v-if="!allMenuShow" @click="allMenuShow = true">
					<div class="x"></div>
					<div class="y"></div>
					<div class="z"></div>
				</div>
				<div class="allMenu_btn open" v-if="allMenuShow" @click="allMenuShow = false">
					<div class="x coll rotate30 rotate45"></div>
					<div class="y coll" style="display: none;"></div>
					<div class="z coll rotate150 rotate135"></div>
				</div>
			</div>

			<div class="page_contents">
				<h3>
					{{title}}
					<p>가입된 아이디와 이메일로 <br>본인인증을 해주세요.</p>
				</h3>

				<form action="" class="form_boundary">
					<div>
						<p>아이디(필수)</p>
						<input type="text" v-model="idcard">
					</div>

					<div class="email_box">
						<p>이메일(필수)</p>
						<div>
							<input type="email" v-model="email">
							<div class="btn open_modal" @click="getCode()">인증요청</div>
						</div>
					</div>
				</form>
			</div>
		</div>

		<nav id="allMenu" v-if="allMenuShow">
			<ul>
				<li>
					<a href="/main">
						<p><i class="xi-home"></i>홈</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/staking">
						<p><i class="xi-bank"></i>상품 구매</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/staking_sum">
						<p><i class="xi-credit-card"></i>상품 구매 합계</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/interest">
						<p><i class="xi-piggy-bank"></i>데일리내역</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/withdraw_apply">
						<p><i class="xi-money"></i>출금신청</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/withdraw_list">
						<p><i class="xi-wallet"></i>출금/송금내역</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/recommender">
						<p><i class="xi-group"></i>추천인 목록</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>

				<li>
					<a href="/mypage">
						<p><i class="xi-profile-o"></i>마이페이지</p>
						<i class="xi-angle-right-min"></i>
					</a>
				</li>
			</ul>

			<div class="btn" @click="logout()">로그아웃</div>
		</nav>

		<div id="passwordModal" class="modal" v-if="showModal">
			<div class="modal_body">
				<form action="" class="form_boundary">
					<section class="sec01">
						<div class="top">
							<img src="../assets/img/icon/email.png" alt="">
							<h3>
								<span>인증 이메일</span>이 <br>발송되었습니다.
								<p>인증코드를 입력해주세요.</p>
							</h3>
						</div>

						<div class="bottom">
							<p>인증번호 입력</p>
							<input type="number" v-model="code">
							<div class="btn next_btn" @click="verify_code()">인증확인</div>
							<button type="button" class="btn close_btn" @click="showModal = false">닫기</button>
						</div>
					</section>

					<section class="sec02">
						<img src="../assets/img/icon/finish_icon.png" alt="">
						<h3>이메일 인증이 <br>완료되었습니다.</h3>
						<button class="btn finish_btn">완료</button>
					</section>
				</form>
			</div>
		</div>
	</div>
</template>
<script>
	import axios from "axios";
	export default {
		data() {
			return {
				idcard: '',
				email: '',
				showModal: false,
				code: '',
				allMenuShow: false,
				title:'비밀번호 찾기',
				
			};
		},
		created() {
			if(this.$route.query.type == 1){
				this.title = '비밀번호 변경';
			}
		},
		methods: {
			// 获取邮箱验证码
			getCode() {
				var _that = this;
				if (!_that.email || !_that.idcard) {
					alert('전체 정보를 입력하십시오.');
					return;
				}
				axios.post('https://admintest.pdt-daily.com/api/login/send_email', {
					email: _that.email
				}).then(function(response) {
					console.log(response);
					if (response.data.status == 400) {
						alert('올바른 메일박스를 입력하십시오.');
					}
					if (response.data.status == 200) {
						_that.showModal = true;
					}
				}).catch(function(error) {
					console.log(error);
				});
			},
			// 邮箱验证
			verify_code() {
				var _this = this;
				if (!_this.email || !_this.idcard || !_this.code) {
					alert('전체 정보를 입력하십시오.');
					return;
				}
				axios.post('https://admintest.pdt-daily.com/api/login/verify_code', {
					user_no: _this.idcard,
					email: _this.email,
					code: _this.code
				}).then(function(response) {
					console.log(response);
					if (response.data.status == 200) {
						_this.$router.push({
							path: '/pw_change',
							query: {
								user_no: _this.idcard
							}
						})
					}
					if (response.data.status == 400) {
						alert('계정 정보가 잘못되었습니다.');
					}
				}).catch(function(error) {
					console.log(error);
				});
			},
			goback() {
				this.$router.back()
			},
			logout() {
				var _this = this;
				axios.post('https://admintest.pdt-daily.com/api/user/logout', {}, {
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded',
						'Access-Token': localStorage.getItem('token')
					}
				}).then(function(response) {
					console.log(response);
					if (response.data.status == 200) {
						alert('로그아웃 되었습니다.');
						localStorage.setItem('token', '');
						_this.$router.push('/login');
					}
				}).catch(function(error) {
					console.log(error);
				});
			}
		},
	};
</script>